package com.gdziarmaga.webshop.book.model;

import java.util.Date;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gdziarmaga.webshop.author.services.AuthorManager;
import com.gdziarmaga.webshop.book.services.BookManager;
import com.gdziarmaga.webshop.client.services.ClientManager;
import com.gdziarmaga.webshop.delivery.services.DeliveryManager;
import com.gdziarmaga.webshop.login.model.Login;
import com.gdziarmaga.webshop.login.services.LoginManager;
import com.gdziarmaga.webshop.review.services.ReviewManager;
import com.gdziarmaga.webshop.transaction.services.TransactionManager;

public class Main {
	
	
	public static void main(String[] args) {
		 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
		
//		 Configuration configuration = new Configuration(ctx);
//		 SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
//	        Session session = sessionFactory.openSession();
//	        Transaction tx = session.beginTransaction();
		    BookManager bookmanager = (BookManager)ctx.getBean("bookManager");
		    ReviewManager revmanager = (ReviewManager)ctx.getBean("reviewManager");
		    AuthorManager authmanager = (AuthorManager)ctx.getBean("authorManager");
		    DeliveryManager delmanager = (DeliveryManager)ctx.getBean("deliveryManager");
		    ClientManager clienmanager = (ClientManager) ctx.getBean("clientManager");
		    LoginManager loginmanager = (LoginManager) ctx.getBean("loginManager");
		    TransactionManager transamanager = (TransactionManager) ctx.getBean("transManager");
		    
//		    tx.begin();
//		    System.out.println(bookmanager.getBook(42L).getBookName());
//		    System.out.println(bookmanager.getBook(7L).getBookName());
		   
//		    Book book = new Book();
//		    book.setIsbn("isbn66");
//		    book.setIssue_year(234);
//		    book.setLong_descripton("asfasdfads");
//		    book.setNumber_of_books(999);
//		    book.setShort_descripton("sdfgsdfgsdfg");
//		    book.setPages(33);
//		    book.setPrice(99.98f);
//		    book.setPublisher("Helion");
//		    book.setSection("sdv");
//		    book.setTitle("Bez ołączeń");
//		    bookmanager.saveBook(book);
//		    System.out.println(bookmanager.getBookId(7L).getTitle());
//		    bookmanager.saveBook(book);
		    
//		    bookmanager.getBookById(126l);
//		    book.getAuthor_set();
//		    book.getBook_client_set();
//		    book.getBook_delivery_set();
//		    book.getReview_list();
		    
//		    BaseFilter baseFilter = new BaseFilter();
//		    bookmanager.getBooksByFilterObject(baseFilter);
//		    baseFilter.addFilterField(new FilterField<String>("1", Review.BOOK_ID, FilterComparisonType.EQUAL));
//		    revmanager.getReviewsByFilterObject(baseFilter);
//		    Book b = bookmanager.getBookById(2L);
//		    authmanager.getAuthorById(2L);
//		    baseFilter.addFilterField(new FilterField<Book>(b, Review.BOOK, FilterComparisonType.EQUAL));
		    
		    
//		    revmanager.getReviewsByFilterObject(baseFilter);
		    
		    
//		    List<Book> set2 = new ArrayList<Book>();
//		    set2.add(bookmanager.getBookById(1L));
//		    set2.add(book);
		    
//		    Review r = new Review();
//		    r.setNick("jakisnowacalkiem3");
//		    r.setReview_date(new Date());
//		    r.setText("tesk");
//		    r.setBook(bookmanager.getBookById(3L));

//		     r.setReview_id(6L);
//		    Book b =  bookmanager.getBookById(101l);
//		    List<Review> set = new ArrayList<Review>();
//		    set.add(r);
//		    bookmanager.saveBook(book);
//		    book.setReview_list(set);

//		    revmanager.saveReview(r);
//		    authmanager.getAuthorByAuthor_first_name("Jan");
//		    authmanager.getAuthorById(1L);
		    
//		    Book d = bookmanager.getBookById(102L);
//		    Set<BookDelivery> set = new HashSet<BookDelivery>();
//		    BookDelivery bd = new BookDelivery();
//		    bd.setBook(book);
//		    bd.setDelivery(delmanager.getDeliveryById(1L));
//		    bd.setNumber_of_delivered_books(17);
//		    set.add(bd);
//		    
//		    book.setBook_delivery_set(set);
//		    bookmanager.saveBook(book);
//		    delmanager.getDeliveryById(1l);
//		    authmanager.getAuthorById(47l);
//		    
//		    Author auth = new Author();
//		    auth.setAuthor_first_name("gryes");
//		    auth.setAuthor_last_name("dziarmaga1");
//		    auth.setBook_list(set2);
//		    
//		    Login log = new Login();
//		    log.setClient(clienmanager.getClientById(6l));
//		    log.setComputer_ip("copmID");
//		    log.setLogin_date(new Date());
//		    loginmanager.saveLogin(log);
//		    authmanager.saveAuthor(auth);
//		    Set<Author> lis = new HashSet<Author>();
//		    lis.add(authmanager.getAuthorById(23l));
//		    lis.add(authmanager.getAuthorById(24l));
//		    book.setAuthor_set(lis);
//		    bookmanager.saveBook(book);
//		    System.out.println(bookmanager.getBookById(63l).getReview_list().toString());
//		    revmanager.getReviewById(27L);
//		    tx.commit();
//			b.getReview_list();
		    
		    
//		    Client c = new Client();
//		    c.setApartment_number(12);
//		    c.setDate_of_birth(GregorianCalendar.getInstance().getTime());
//		    c.setEmail("email");
//		    c.setFirst_name("jutrek");
//		    c.setHouse_number(2);
//		    c.setLast_name("54");
//		    c.setPasswd("pasew");
//		    c.setPhone("54erd");
//		    c.setPost("laczna");
//		    c.setPostal_code("6dfg4");
//		    c.setStreet("sienkiewicza");
//		    clienmanager.saveClient(c);
//		    clienmanager.getClientById(6l);
//		    loginmanager.getLoginById(24l);
//		    transamanager.getTransactionById(1l);
//		    BookFilterBean filter = new BookFilterBean();
//			filter.setSection(new FilterField<String>("Java", Book.SECTION, FilterComparisonType.LIKE_CASE_INSENSITIVE));
//		    filter.addFilterField(filter.getSection());
//			bookmanager.getBooksByFilterObject(filter);
		    
		    Login login = new Login();
		    login.setClient(clienmanager.getClientById(3L));
		    login.setLogin_date(new Date());
		    loginmanager.saveLogin(login);
	}

}
